using System;

namespace org.paulbanks.BarcodeDotNet.Encoders
{	
	/// Code 128 Barcode Encoder class	
	public class Code128 : BarcodeEncoder {

		protected static string[] codeset = {
			"212222", "222122", "222221", "121223", "121322",  /*  0 -  4 */
			"131222", "122213", "122312", "132212", "221213",
			"221312", "231212", "112232", "122132", "122231",  /* 10 - 14 */
			"113222", "123122", "123221", "223211", "221132",
			"221231", "213212", "223112", "312131", "311222",  /* 20 - 24 */
			"321122", "321221", "312212", "322112", "322211",
			"212123", "212321", "232121", "111323", "131123",  /* 30 - 34 */
			"131321", "112313", "132113", "132311", "211313",
			"231113", "231311", "112133", "112331", "132131",  /* 40 - 44 */
			"113123", "113321", "133121", "313121", "211331",
			"231131", "213113", "213311", "213131", "311123",  /* 50 - 54 */
			"311321", "331121", "312113", "312311", "332111",
			"314111", "221411", "431111", "111224", "111422",  /* 60 - 64 */
			"121124", "121421", "141122", "141221", "112214",
			"112412", "122114", "122411", "142112", "142211",  /* 70 - 74 */
			"241211", "221114", "413111", "241112", "134111",
			"111242", "121142", "121241", "114212", "124112",  /* 80 - 84 */
			"124211", "411212", "421112", "421211", "212141",
			"214121", "412121", "111143", "111341", "131141",  /* 90 - 94 */
			"114113", "114311", "411113", "411311", "113141",
			"114131", "311141", "411131", "b1a4a2", "b1a2a4",  /* 100 - 104 */
			"b1a2c2", "b3c1a1b"
		};
	
		protected const byte START_A = 103;
		protected const byte START_B = 104;
		protected const byte START_C = 105;
		protected const byte STOP = 106;
		protected const byte SHIFT = 98;
		protected const byte CODE_A = 101;
		protected const byte CODE_B = 100;
		protected const byte CODE_C = 99;
		protected const byte FUNC_1 = 102;
		protected const byte FUNC_2 = 97;
		protected const byte FUNC_3 = 96;		

		protected const byte SYMBOL_WID = 11;

		private Code128 enc;

		public enum Code128Type {
			CODE_128A,
			CODE_128B,
			CODE_128C					
		}

		protected Code128() {			
		}

		public Code128(Code128Type BarcodeType) {

			switch (BarcodeType) {
				/*case Code128Type.CODE_128_AUTO:
					enc = null;
					break;*/
				case Code128Type.CODE_128A:
					enc = new Code128_AB(Code128_AB.ABType.A);
					break;
				case Code128Type.CODE_128B:
					enc = new Code128_AB(Code128_AB.ABType.B);
					break;
				case Code128Type.CODE_128C:
					enc = new Code128_C();
					break;
			}

		}

		override public bool Verify(string strText) {
			return enc.Verify(strText);
		}

		override public string Encode(string strText) {
			return enc.Encode(strText);
		}	

	}
}
